package likong.bibliothek.pages.autor;

import org.apache.wicket.PageParameters;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;

import likong.bibliothek.obj.Autor;

import db.HibernateHelper;

public class AutorNeu extends AutorAbstract {
	public AutorNeu(){
		Autor autor = new Autor();
		final CompoundPropertyModel<Autor> model = new CompoundPropertyModel<Autor>(autor);
		
		// Panel einfügen
		add(new AutorFormPanel("neuerAutorFormular", model, "Autor einfügen") {
			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmitModelHandle(IModel<Autor> model) {
				Integer id = (Integer) HibernateHelper.save(model.getObject());
				
				//Redirect
				PageParameters params = new PageParameters();
				params.add("autorID", id.toString());
				
				this.setRedirect(true);
				this.setResponsePage(AutorWeb.class, params);
			}
			
			@Override
			protected void onBackButtonClick() {
				this.setRedirect(true);
				this.setResponsePage(AutorWeb.class);
			}
		});
	}

}
